package edu.xkd.slice;

import edu.xkd.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //关联一个界面布局文件
        super.setUIContent(ResourceTable.Layout_ability_main);

        //写关于界面的后台业务逻辑
        //获取界面中按钮对象
        Button button_01 = (Button) this.findComponentById(ResourceTable.Id_button_01);
        Button button_02 = (Button) this.findComponentById(ResourceTable.Id_button_02);
        //为按钮对象添加单击事件
        button_01.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                toastDialog.setText("按钮被单击了~");
                toastDialog.show();
            }
        });
        button_02.setClickedListener(this::clickedListenerButton02);
    }

    private void clickedListenerButton02(Component component) {
        ToastDialog toastDialog = new ToastDialog(this);
        toastDialog.setText("鸿蒙操作系统特有的绑定事件处理方法");
        toastDialog.show();
    }


    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
